<template>
  <view-box body-padding-bottom="5px">
    <empty tips="暂无评价" icon="icon-daipingjia" v-if="list !== null && list.length === 0"></empty>
    <div class="p-comments-list">
      <div class="p-comments-item" :class="{'vux-1px-b' : list.length !== index + 1}" v-for="(comment, index) in list" :key="comment.id">
        <div class="p-comments-item-title">
          <img v-if="!comment.user.avatar" src="/static/thumb-small.png">
          <img v-else :src="comment.user.avatar">
          <span class="p-comments-item-name">{{comment.user.name}}</span>
          <span class="p-comments-item-time">{{comment.created_at}}</span>
        </div>
        <div class="p-comments-item-content">
          {{comment.content}}
        </div>
        <div class="p-comments-item-spec">
          <span data-reactid="280">{{comment.order_goods.spec_value}}</span>
        </div>
      </div>
    </div>
  </view-box>
</template>
<script type="text/javascript">
import Empty from '@/views/components/Empty'
import { ViewBox } from 'vux'
export default {
  data () {
    return {
      goods_id: null,
      list: null
    }
  },
  components: {
    ViewBox,
    Empty
  },
  mounted () {
    this.goods_id = this.$route.params.product
    this._getData()
  },
  methods: {
    _getData () {
      this.$vux.loading.show()
      this.$http.get('/comments?goods_id=' + this.goods_id).then((response) => {
        this.$vux.loading.hide()
        this.list = response.data.data
      }).catch((error) => {
        this.$vux.loading.hide()
        console.log(error)
      })
    }
  }
}
</script>
<style scoped lang="less">
  .p-comments-list {
    background: #fff;
    padding: 0 10px;
  }
  .p-comments-item {
    padding-top: 5px;
    padding-bottom: 15px;
  }
  .p-comments-item-title {
    height: 25px;
    margin: 10px 0;
    line-height: 25px;
  }
  .p-comments-item-title img {
    float: left;
    height: 25px;
    width: 25px;
    border-radius: 100%;
    margin-right: 7px;
    border: 1px solid #e0e0e0;
  }
  .p-comments-item-name {
    color: #151516;
    white-space: nowrap;
    -webkit-line-clamp: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    -webkit-box-orient: vertical;
    text-align: left;
  }
  .p-comments-item-time {
    float: right;
    color: #9c9c9c;
    display: block;
    font-size: 13px;
  }
  .p-comments-item-content {
    width: 100%;
    max-height: 40px;
    color: #58595b;
    word-break: break-all;
    word-wrap: break-word;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    -webkit-box-orient: vertical;
    text-align: left;
  }
  .p-comments-item-spec {
    font-size: 12px;
    color: #9c9c9c;
    margin-top: 7px;
    width: 100%;
    word-break: break-all;
    line-height: 1;
  }
</style>